//
//  UITabBarItem+DY.m
//  DYLYJ
//
//  Created by JM on 15/10/27.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "UIBarButtonItem+DY.h"
#import "DYNavigationCOntroller.h"
@implementation UIBarButtonItem (DY)

+ (UIBarButtonItem *)backBarItemWithTarget:(nullable id)target action:(SEL)action {
    // create your button
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.exclusiveTouch = YES;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"backBtn"]forState:UIControlStateNormal];
    
    button.frame = CGRectMake(0, -(kDYBarHeight-44)/2.0, 44, 45);
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, button.frame.size.width, button.frame.size.height)];
    [view addSubview:button];
    
    // set the barbuttonitem to be the view
    return [[UIBarButtonItem alloc] initWithCustomView:view];


}

+ (UIBarButtonItem *)editBarItemWithTarget:(nullable id)target action:(SEL)action  {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
     button.exclusiveTouch = YES;
    [button setImage:[UIImage imageNamed:@"editBtn"]forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, -(kDYBarHeight-44)/2.0, 44, 45);
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, button.frame.size.width, button.frame.size.height)];
    [view addSubview:button];
    return [[UIBarButtonItem alloc]initWithCustomView:view];

}

+ (UIBarButtonItem *)barItemWithImageName:(NSString *)imageName Target:(nullable id)target action:(SEL)action {
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0,0,44,45)];
    [button setImage:[UIImage imageNamed:imageName]forState:UIControlStateNormal];
     button.frame = CGRectMake(0, -(kDYBarHeight-44)/2.0, 44, 45);
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, button.frame.size.width, button.frame.size.height)];
    [view addSubview:button];
    return [[UIBarButtonItem alloc]initWithCustomView:view];
}
@end
